<template>
  <div class="tab-bar-item" @click="itemClick">
    <slot v-if="isActive" name="item-img-active"></slot>
    <slot v-else name="item-img"></slot>
    <div :class="{active: isActive}">
      <slot name="item-txt"></slot>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      path: String
    },
    data() {
      return {
        // isActive: false
      }
    },
    computed: {
      isActive() {
        return this.$route.path.indexOf(this.path) !== -1;
      }
    },
    methods: {
      itemClick() {
        this.$router.replace(this.path)
      }
    },
  }
</script>

<style>
  .tab-bar-item {
    flex: 1;
    text-align: center;
  }
  .tab-bar-item img {
    width: 24px;
    height: 24px;
  }
  .tab-bar-item p {
    font-size: 12px;
  }
  .active {
    color: red;
  }
</style>